#include <stdio.h>
#include <string.h>
#include "queue0.h"

void createQueue(Queue *pq)
{
	memset(pq->data,0,MAX_QSIZE * sizeof(Item));
	pq->front = pq->rear = 0;
	pq->len = 0;
}

BOOL qIsFull(Queue *pq)
{
	//return ((pq->rear + 1) % MAX_QSIZE == pq->front);
	return pq->len == MAX_QSIZE;
}

BOOL qIsEmpty(Queue *pq)
{
	return pq->len == 0;
}

int queue_length(Queue *pq)
{
	return pq->len;
}

BOOL enItem(Queue *pq,const Item item)
{
	if (qIsFull(pq)){
		return FALSE;
	}
	pq->data[pq->rear] = item;
	pq->rear = (pq->rear + 1) % MAX_QSIZE;
	pq->len++;
	return TRUE;
	
}

BOOL deItem(Queue *pq,Item *pitem)
{
	if (qIsEmpty(pq)){
		return FALSE;
	}
	*pitem = pq->data[pq->front];
	pq->front = (pq->front + 1) % MAX_QSIZE;
	pq->len--;
	return TRUE;
}


